8372. Create a triangle

 

Given the lengths of three segments, determine if they can form a non-degenerate triangle. A triangle is considered non-degenerate if its area is greater than 0.

 

Input. Three positive integers a, b, c (1 ≤ a, b, c ≤ 1000) – the lengths of three segments.

 

Output. Print “YES” if the segments can form a non-degenerate triangle, and “NO” otherwise.

 

Sample input 1

Sample output 1

5 6 7

YES

 

 

Sample input 2

Sample output 2

3 7 4

NO

 

 

SOLUTION

conditional statement

 

Algorithm analysis

Let a, b, and c be the lengths of three segments. These segments can form a non-degenerate triangle if the sum of the lengths of any two segments is greater than the length of the third segment. This condition is known as the triangle inequality:

a < b + c && b < a + c && c < a + b

 

Algorithm implementation

Read the input data.

 

scanf("%d %d %d",&a,&b,&c);

 

Check the triangle inequality and print the answer.

 

if (a < b + c && b < a + c && c < a + b)

  printf("YES\n");

else

  printf("NO\n");

 

Java implementation

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    int a = con.nextInt();

    int b = con.nextInt();

    int c = con.nextInt();

   

    if (a < b + c && b < a + c && c < a + b)

      System.out.println("YES");

    else

      System.out.println("NO");

    con.close();

  }

}  

 

Python implementation

Read the input data.

 

a, b, c = map(int, input().split())

 

Check the triangle inequality and print the answer.

 

if a < b + c and b < a + c and c < a + b:

  print("YES\n")

else:

  print("NO\n")